package leetcode_day._2022._202209._0110;

/**
 * 1582. 二进制矩阵中的特殊位置
 * 算法：模拟
 *
 * @author yzh
 * @version 1.0
 * @date 2022/9/4 18:05
 */
public class _04 {

    public int numSpecial(int[][] mat) {
        int m = mat.length, n = mat[0].length;
        int[] rs = new int[m], cs = new int[n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                rs[i] += mat[i][j];
                cs[j] += mat[i][j];
            }
        }
        int ans = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++)
                if (mat[i][j] == 1 && rs[i] == 1 && cs[j] == 1) ++ans;
        }
        return ans;
    }

}
